// 手机号码验证规则
export const validatePhone = (rule, value, callback) => {
  const reg = /^1[3-9]\d{9}$/;
  if (value === "") {
    callback(new Error("手机号码不能为空"));
  } else if (!reg.test(value)) {
    callback(new Error("请输入正确的手机号码"));
  } else {
    callback();
  }
};

// 银行账号验证
export const bankAccountValid = (rule, value, callback) => {
  // 基本格式验证
  const regex = /^[0-9]{12,24}$/;
  if (!regex.test(value)) {
    callback(new Error("请输入正确格式的银行卡号"));
  }else{
    callback();
  }
};

// 身份证验证
export const idCardValid = (rule, value, callback) => {
  const regIdCard =
    /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
  if (value === "") {
    callback(new Error("身份证号码不能为空"));
  } else if (!regIdCard.test(value)) {
    callback(new Error("身份证号码格式不正确"));
  } else {
    callback();
  }
};

/* 纳税人识别号 */
export const isidentifyNumber = (rule, value, callback) => {
  if (!value) {
    callback();
  } else {
    const reg = /^[A-Z0-9]{15}$|^[A-Z0-9]{17}$|^[A-Z0-9]{18}$|^[A-Z0-9]{20}$/;
    const identifyNumber = reg.test(value);
    if (!identifyNumber) {
      callback(new Error("填写正确纳税人识别号"));
    } else {
      callback();
    }
  }
};

/* 验证统一社会信用代码  */
export const checkSocialCreditCode = (rule, value, callback) => {
  const regCreditCode = /^([0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}|[1-9]\d{14})$/;
  if(value === ''){
    callback(new Error("统一社会信用代码不能为空"));
  }else if (!regCreditCode.test(value)) {
    callback(new Error("统一社会信用代码格式不正确"));
  } else {
    callback();
  }
};
